package com.gee.spring.cloud.data.transform.core.center.config.handler;

import com.gee.spring.cloud.common.core.entity.center.config.SocketConfig;
import com.gee.spring.cloud.common.starter.config.event.CenterConfigEventHandler;
import com.gee.spring.cloud.data.transform.core.dispatch.SocketManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author gepengjun
 * @since 2024/3/19 14:38
 */
@Component
public class SocketConfigHandler extends CenterConfigEventHandler<SocketConfig> {

    @Autowired
    private SocketManager socketManager;


    @Override
    public void handleAdd(List<SocketConfig> dataList) {
        dataList.forEach(socketConfig -> {
            socketManager.addSocketConfig(socketConfig);
        });
    }

    @Override
    public void handlerUpdate(List<SocketConfig> dataList, List<SocketConfig> oldList) {
        dataList.forEach(socketConfig -> {
            socketManager.updateSocketConfig(socketConfig);
        });
    }

    @Override
    public void handlerDelete(List<SocketConfig> oldList) {
        oldList.forEach(socketConfig -> {
            socketManager.removeSocketConfig(socketConfig);
        });
    }

}
